﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ImageUploader.domain;
using System.IO;
using System.DirectoryServices;

namespace ImageUploader.GUI
{
    public partial class NewUsersForm : Form
    {
        private User myUser;
        private DomainController dc;

        public NewUsersForm(DomainController dc)
        {
            myUser = new User();
            this.dc = dc;
            InitializeComponent();
            txtDistinguishedName.Text = "CN=Users";
            this.StartPosition = FormStartPosition.CenterScreen;
        }

        private void btnEditUser_Click(object sender, EventArgs e)
        {
            
            try
            {
                using (DirectoryEntry de = dc.LDAPConnection.CreateDirectoryEntryWithDomainName(txtDistinguishedName.Text))
                {
                    DirectorySearcher search = new DirectorySearcher(de, "(objectClass=User)");
 
                        myUser.searchResult = new SearchResult();
                        myUser.Save(txtDistinguishedName.Text);
                    }



                }
            }
            catch (Exception exc)
            {
                labelMessage.Text = "Directory not found";
                txtDistinguishedName.Text = "CN=Users";
                return;
            }

            EditForm ef = new EditForm(myUser);
            ef.Show();

            this.Close();

        }
    }
}